package com.jiyang.jyandroid.test03;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.jiyang.jyandroid.BaseActivity;
import com.jiyang.jyandroid.R;
import com.jiyang.jyandroid.bean.Book;
import com.jiyang.jyandroid.other.BookFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jy on 2016/12/1.
 * 显示图书详情o
 */

public class Three_3Activity extends BaseActivity {
    private String[] strings = {"Java入门讲义", "Android疯狂讲义", "C语言基础", "数据库原理", "Unity3D开发"};
    private List<Book> bookList;
    private BookFragment bookFragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_library);
        bookList = new ArrayList<>();
        bookList.add(new Book("Java入门讲义", "Java入门讲义，主要面向没有Java语言基础的同学"));
        bookList.add(new Book("Android疯狂讲义", "Android疯狂讲义主要面向没有Android开发基础的同学"));
        bookList.add(new Book("C语言基础", "C语言基础主要面向没有C语言基础的同学"));
        bookList.add(new Book("数据库原理", "数据库基础主要面向没有数据库基础的同学"));
        bookList.add(new Book("Unity3D开发", "Unity3D主要面向没有Unity3D基础的同学"));

        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, strings);
        ListView listView = (ListView) findViewById(R.id.list_library);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                bookFragment.setData(bookList.get(i));
            }
        });
        bookFragment = new BookFragment();
        //显示fragment
        getSupportFragmentManager().beginTransaction().add(R.id.frame_library_details, bookFragment).commit();
    }

}
